package com.wu.example;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;

public class BrowserView extends Activity {

	private WebView webView;

	private EditText url_field;
	private Button go_button;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		webView = (WebView) findViewById(R.id.web_view);
		// get a handle to all user interface elements
		url_field = (EditText) findViewById(R.id.url_field);
		go_button = (Button) findViewById(R.id.go_button);

		go_button.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				openBrowser();
			}
		});

		url_field.setOnKeyListener(new View.OnKeyListener() {

			@Override
			public boolean onKey(View view, int keyCode, KeyEvent event) {
				if (keyCode == KeyEvent.KEYCODE_ENTER) {
					openBrowser();
					return true;
				}
				return false;
			}
		});
	}

	/**
	 * open a browser on the URL specified in the text box
	 */
	protected void openBrowser() {
		webView.getSettings().getJavaScriptEnabled();
		webView.loadUrl(url_field.getText().toString());
		// webView.setWebViewClient(client)
		// WebViewClient.
	}

}